package com.zmn.plat.dubbo.impl.orderconfig.returnvisitcontent;

import java.util.List;

import javax.annotation.Resource;

import org.apache.dubbo.config.annotation.Service;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.plat.business.interfaces.orderconfig.returnvisitcontent.ReturnVisitAnswerBService;
import com.zmn.plat.common.dto.orderconfig.returnvisitcontent.ReturnVisitAnswerDIO;
import com.zmn.plat.common.dto.orderconfig.returnvisitcontent.ReturnVisitAnswerDRO;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.dubbo.interfaces.orderconfig.returnvisitcontent.ReturnVisitAnswerListRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;

import lombok.extern.slf4j.Slf4j;

/**
 * 类描述:回访答案dubbo接口实现类
 *
 * @auther: tanghongjun
 * @since: 2020年4月15日11:27:03
 */
@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
@Slf4j
public class ReturnVisitAnswerListRemoteServiceImpl implements ReturnVisitAnswerListRemoteService {

    @Resource
    ReturnVisitAnswerBService returnVisitAnswerBService;

    @Override
    @ReadOnlyConnection
    public ResponseDTO<ReturnVisitAnswerDRO> getById(Integer answerId) {
        log.info("getById 参数为：answerId={}", answerId);
        try {
            ReturnVisitAnswerDRO dro = returnVisitAnswerBService.getById(answerId);
            return ResponseDTO.success(dro);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("getById error.answerId={}", answerId, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }

    @Override
    @ReadOnlyConnection
    public ResponseDTO<List<ReturnVisitAnswerDRO>> listByQuery(ReturnVisitAnswerDIO returnVisitAnswerDIO) {
        log.info("listByQuery 参数为：returnVisitAnswerDIO={}", returnVisitAnswerDIO);

        try {
            List<ReturnVisitAnswerDRO> dro = returnVisitAnswerBService.listByQuery(returnVisitAnswerDIO);
            return ResponseDTO.success(dro);
        } catch (PlatException e) {
            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
        } catch (Exception e) {
            log.error("getById error.returnVisitAnswerDIO={}", returnVisitAnswerDIO, e);
            return ResponseDTO.fail(GlobalConsts.FAILD_MSG);
        }
    }
}
